<?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id'=>'searchForm',
    'type'=>'search',
    'htmlOptions'=>array('class'=>'well'),
)); ?>
<?php echo $form->textFieldRow($model, 'task_id', array('class'=>'input-xlarge', 'prepend'=>'<i class="icon-search"></i>')); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'label'=>'搜索')); ?>
<?php $this->endWidget(); ?>

<?php /** @var BootActiveForm $form */
    $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id'=>'job',
    'type'=>'horizontal',
    'enableClientValidation'=>true,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
    ),
)); ?>
<script>
function reloadGrid(data) {
    $.fn.yiiGridView.update('task-grid');
}
function checkSelect() {                                                  
    if($.fn.yiiGridView.getSelection("task-grid") == "") {
        alert('请选择至少一条记录');                                                    
        return false;                                                  
    }
    else {
        return true;
    }
}
</script>
<div class="btn-toolbar">

<?php $this->widget('bootstrap.widgets.TbButton', array(
    'type'=>'danger',
    'buttonType'=>'ajaxSubmit',
    'size'=>'small',
    'icon'=>'remove white',
    'label'=>'批量删除', 
    'url'=>array('task/ajaxDelete'), 
    'ajaxOptions'=>array(
        'beforeSend'=>  'checkSelect',
        'success'   =>  'reloadGrid',
    ),
    'htmlOptions'=>array(
        'confirm'=>'确认要删除吗?',
    ),

)); ?>

<?php $this->widget('bootstrap.widgets.TbButton', array(
    'type'=>'primary',
    'buttonType'=>'ajaxSubmit',
    'label'=>'杀死任务',
    'icon'=>'remove-circle white',
    'url'=>array('task/kill', 'type' => $_GET['type']),
    'size'=>'small',
    'ajaxOptions'=>array(
        'beforeSend'=>  'checkSelect',
        'success'   =>  'reloadGrid',
    ),
    'htmlOptions'=>array(
        'confirm'=>'确认要杀死任务吗?',
    ),

)); ?>

<?php $this->widget('bootstrap.widgets.TbButton', array(
    'type'=>'primary',
    'buttonType'=>'ajaxSubmit',
    'label'=>'恢复执行',
    'icon'=>'wrench white',
    'url'=>array('task/resume', 'type' => $_GET['type']),
    'size'=>'small',
    'ajaxOptions'=>array(
        'beforeSend'=>  'checkSelect',
        'success'   =>  'reloadGrid',
    ),
    'htmlOptions'=>array(
        'confirm'=>'确认要恢复执行吗?',
    ),
)); ?>

<?php $this->widget('bootstrap.widgets.TbButton', array(
    'type'=>'primary',
    'buttonType'=>'ajaxSubmit',
    'label'=>'重新运行',
    'icon'=>'refresh white',
    'url'=>array('task/rerun', 'type' => $_GET['type']),
    'size'=>'small',
    'ajaxOptions'=>array(
        'beforeSend'=>  'checkSelect',
        'success'   =>  'reloadGrid',
    ),
    'htmlOptions'=>array(
        'confirm'=>'确认要重新运行吗?',
    ),
)); ?>

</div>
<?php $this->widget('bootstrap.widgets.TbGridView', array(
	'id' => 'task-grid',
    'type'=>'striped bordered condensed',
    'dataProvider'  =>  $dataProvider,
    'pager'=>array(
        'class'=>'CLinkPager',           
        'nextPageLabel'=>'下一页',           
        'prevPageLabel'=>'上一页',           
        'header'=>'',   
    ),   
    'selectableRows' => 2,
    'summaryText'   =>  '显示{start}-{end}条.共{count}条记录,当前第{page}页',
    'template'      =>  '{items}{pager}',
    'columns'       =>  array(
        array(
            'id'    =>  'autoId',
            'class' =>  'CCheckBoxColumn',
        ),
       array(
            'header' => '#',
            'name'  =>  'task_id',
            'value' =>  '$data->task_id'
        ), 
        array(
            'header'=>  '任务名称',
            'name'  =>  'job_name',
            'type'  =>  'raw',
            'value' =>  'CHtml::link(CHtml::encode($data->job->job_name), $data->url)'
        ),
        array(
            'name'  =>  'date',
            'value' =>  'substr($data->date, 0, 16)',
        ),
        array(
            'header'=>  '类型',
            'name'  =>  'task_type',
            'value' =>  'TaskType::$names[$data->task_type]'
        ),
        array(
            'header'=>  '周期',
            'name'  =>  'frequency',
            'value' =>  'Frequency::$names[$data->frequency]'
        ),
        array(
            'name'  =>  'start_time',
            'value' =>  '$data->start_time'
        ), 
        array(
            'name'  =>  'end_time',
            'value' =>  '$data->end_time'
        ), 
        array(
            'header'=>  '状态',
            'name'  =>  'state',
            'value' =>  'TaskState::$names[$data->state]',
        ),
        array(
            'class' =>  'bootstrap.widgets.TbButtonColumn',
            'template'=>'{delete}',           
            'buttons'=>array(
                'delete'   =>  array(
                    'label'     =>  '删除任务',
                    'url'      =>  'Yii::app()->controller->createUrl("task/delete", array("id"=>$data->task_id))',
                ),
            ),
        ), 
    ),
));
?>
<?php $this->endWidget(); ?>
